var PeopleMedia = PeopleMedia || {};
PeopleMedia.Homepage = new function () {
    this.Actions = {};
    this.flirting = false;
    this.favoriting = false;
    this.sendFlirt = function (encodedMemberId, featureName, replyToMessageId, actionType) {
        if (PeopleMedia.Homepage.flirting)
            return;
        PeopleMedia.Homepage.flirting = true;
        var $linkedOverlay = $jq('[Flirt=' + encodedMemberId+']');
        $linkedOverlay.each(function() { $jq(this).parent().find('.flirtoverlayplace').fadeIn('fast');});
            $jq.ajax({
                type: 'POST',
                url: PeopleMedia.Homepage.Actions.SendFlirt,
                data: { EncodedMemberId: encodedMemberId, FeatureName: featureName, ReplyToMessageId: replyToMessageId, ActionType: actionType },
                success: function (response) {
                    PeopleMedia.ReloadAds();
                    PeopleMedia.Homepage.flirting = false;
                    if (response.status == "Success") {
                        $linkedOverlay.each(function() { $jq(this).parent().find('.flirtoverlayplace').delay(2000).fadeOut('slow',function() { $jq(this).hide();});});
                    } else if (response.redirect) {
                        location.href = response.redirect;
                    }
                }
            });
        };
    
    this.toggleFavorite = function (encodedMemberId,addToFavs, featureName, actionType) {
        if (PeopleMedia.Homepage.favoriting)
            return;
        PeopleMedia.Homepage.favoriting = true;
        var url = null;
        if (addToFavs) {
          $jq('[Fav=' + encodedMemberId +']').show();
          $jq('[UnFav=' + encodedMemberId + ']').hide();
            url = PeopleMedia.Homepage.Actions.AddFavorite;
        } else {
          $jq('[UnFav=' + encodedMemberId + ']').show();
          $jq('[Fav=' + encodedMemberId + ']').hide();
            url = PeopleMedia.Homepage.Actions.UnFavorite;
        }
        $jq.ajax({
            type: 'POST',
            url: url,
            data: { EncodedMemberId: encodedMemberId, FeatureName: featureName, ActionType: actionType },
            success: function (response) {
                //PeopleMedia.ReloadAds();
                PeopleMedia.Homepage.favoriting = false;
                if (response.status == "Success") {
                } else {
                    PeopleMedia.Homepage.handleError(response);
                }
            }
        });
    };

    this.showError = function (message) {
        alert(message);
    };
    this.handleError = function (response) {
        if (response.redirect) {
            location.href = response.redirect;
        } else if (response.message) {
            this.showError(response.message);
        }
    };



    this.init = function () {
$jq(document).ready(function() {
    $jq("#myfavoritetab").click(function() {
        $jq("#myfavoritetab").removeClass("myfavoriteoff color-main");
        $jq("#myfavoritetab").addClass("myfavoriteon");
      $jq("#remembertotab").removeClass("myfavoriteon");
      $jq("#remembertotab").addClass("myfavoriteoff color-main");
      $jq("#remembertocontent").hide();
      $jq("#myfavaritecontent").show();
      PeopleMedia.ReloadAds();
});
        $jq("#remembertotab").click(function() {
        $jq("#myfavoritetab").removeClass("myfavoriteon");
        $jq("#myfavoritetab").addClass("myfavoriteoff color-main");
      $jq("#remembertotab").removeClass("myfavoriteoff color-main");
      $jq("#remembertotab").addClass("myfavoriteon");
      $jq("#remembertocontent").show();
      $jq("#myfavaritecontent").hide();
      PeopleMedia.ReloadAds();
      });

    $jq("#successstorytab").click(function() {
        $jq("#successstorytab").removeClass("myfavoriteoff color-main");
        $jq("#successstorytab").addClass("myfavoriteon");
      $jq("#relatedarticlestab").removeClass("myfavoriteon");
      $jq("#relatedarticlestab").addClass("myfavoriteoff color-main");
      $jq("#relatedarticlescontent").hide();
      $jq("#successstorycontent").show();
      PeopleMedia.ReloadAds();
});
        $jq("#relatedarticlestab").click(function() {
        $jq("#successstorytab").removeClass("myfavoriteon");
        $jq("#successstorytab").addClass("myfavoriteoff color-main");
      $jq("#relatedarticlestab").removeClass("myfavoriteoff color-main");
      $jq("#relatedarticlestab").addClass("myfavoriteon");
      $jq("#relatedarticlescontent").show();
      $jq("#successstorycontent").hide();
      PeopleMedia.ReloadAds();
      });
 });


    };

    $jq(document).ready(function () {
        PeopleMedia.Homepage.init();
    });
};


  
